package com.lovo.test.ATM;

import com.lovo.test.Util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//菜单界面
public class MenuPanel extends JPanel implements ActionListener{
    //以下是图片封装
    private Icon storeImg = Util.getIcon("/ATMimages/buttonSave.jpg");//存钱按键
    private Icon takeImg = Util.getIcon("/ATMimages/buttonGet.jpg");//取钱按键
    private Icon checkImg = Util.getIcon("/ATMimages/buttonFind.jpg");//查询按键
    private Icon returnImg = Util.getIcon("/ATMimages/buttonOff.jpg");//返回按键



    private JButton returnBut;//返回按钮
    private JButton takeBut;//取款按钮进入取款界面
    private JButton storeBut;//存款按钮进入存款界面
    private JButton checkBut;//查询按钮进入查询界面
    private ATM frame;


   public  MenuPanel(ATM frame){
        this.frame=frame;
       //空布局
       this.setLayout(null);
       //设置透明
       this.setOpaque(false);

       //存钱按钮进入存钱界面
       storeBut = new JButton(storeImg);
       storeBut.setBounds(100,100,140,50);
       this.add(storeBut);
       storeBut.addActionListener(this);

       //取钱按钮进入取钱界面
       takeBut = new JButton(takeImg);
       takeBut.setBounds(100,200,140,50);
       this.add(takeBut);
       takeBut.addActionListener(this);

       //查询按钮进入查询界面
       checkBut = new JButton(checkImg);
       checkBut.setBounds(100,300,140,50);
       this.add(checkBut);
       checkBut.addActionListener(this);

       //返回按钮返回登陆界面
       returnBut = new JButton(returnImg);
       returnBut.setBounds(350,280,140,50);
       this.add(returnBut);
       returnBut.addActionListener(this);

   }


   //关联方法
    @Override
    public void actionPerformed(ActionEvent e) {
       if (e.getSource()==returnBut){
           frame.switchPanel("登录");//跳转到登录界面
       }else if (e.getSource()==takeBut){
           frame.switchPanel("取款");//跳转到取款界面
       }else if (e.getSource()==storeBut){
           frame.switchPanel("存款");//跳转到存款界面
       }else if (e.getSource()==checkBut){
           frame.switchPanel("查询");//跳转到查询界面
       }

    }
}
